package com.mk.seckill.controller;

import com.mk.seckill.service.IUserService;
import com.mk.seckill.vo.LoginVo;
import com.mk.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller// @RestController = @Controller + @ResponseBody
@RequestMapping("/login")
@Slf4j// 输出日志
public class LoginController {

	@Autowired
	private IUserService userService;

	@RequestMapping("/toLogin")
	public String toLogin(){
		/**
		 * @Author hhwu
		 * @Description //TODO 跳转到登录页面
		 * @Date 19:31 2022/6/6
		 * @Param []
		 * @return java.lang.String
		 **/
		return "login";
	}

	@RequestMapping("/doLogin")
	@ResponseBody
	// @Valid注解会调用validation组件进行LoginVo参数校验，前提是在LoginVo类中进行了配置。这可以省去service中的手动校验
	public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request, HttpServletResponse response){
		/**
		 * @Author hhwu
		 * @Description //TODO 登录功能
		 * @Date 19:31 2022/6/6
		 * @Param [loginVo, request, response]
		 * @return com.xxxx.seckill.vo.RespBean
		 **/
//		log.info("{}", loginVo);// @Slf4j使得此处的log可以直接使用
//		return null;
		return userService.doLogin(loginVo,request,response);
	}

}